package com.ticket.sass.admin.controller;


import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.ticket.sass.admin.annotation.Loggable;
import com.ticket.sass.admin.annotation.Module;
import com.ticket.sass.admin.business.AdminBusiness;
import com.ticket.sass.admin.business.impl.AdminBusinessImpl;
import com.ticket.sass.admin.dto.input.admin.AdminAddInput;
import com.ticket.sass.admin.dto.input.admin.AdminListInput;
import com.ticket.sass.admin.dto.input.admin.AdminUpdInput;
import com.ticket.sass.admin.dto.input.admin.AdminUpdPasswordInput;
import com.ticket.sass.admin.dto.output.admin.AdminListOutput;
import com.ticket.sass.admin.model.PageModel;
import com.ticket.sass.admin.model.ResultModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ywb
 * @since 2024-03-07
 */

@RestController
@ApiSupport(order = 11)
@RequestMapping("/admins")
@Api(tags = {"管理员-模块"})
public class AdminController {
    
    final AdminBusiness business;
    
    public AdminController(AdminBusinessImpl business) {
        this.business = business;
    }
    
    @GetMapping
    @ApiOperation("列表")
    public ResultModel<PageModel<AdminListOutput>> list(
        @Valid AdminListInput input
    ){
        return ResultModel.success(
            business.list(input)
        );
    }
    
    @PostMapping
    @ApiOperation(value = "添加")
    @Loggable(module = Module.ADMIN, desc = "添加管理员")
    public ResultModel<String> add(
        @RequestBody @Valid AdminAddInput input
    ) {
        business.add(input);
        return ResultModel.success();
    }
    
    @PutMapping
    @ApiOperation("修改")
    @Loggable(module = Module.ADMIN, desc = "修改管理员")
    public ResultModel<String> upd(
        @RequestBody @Valid AdminUpdInput input
    ){
        business.upd(input);
        return ResultModel.success();
    }
    
    @PutMapping("/password")
    @ApiOperation(value = "修改密码")
    @Loggable(module = Module.ADMIN, desc = "修改管理员密码")
    public ResultModel<String> updPassword(
        @RequestBody @Valid AdminUpdPasswordInput input
    ){
        business.updPassword(input);
        return ResultModel.success();
    }
    
}
